from pathlib import Path

from docx import Document
from typing import List, Dict

def extract_headings(file_path: str) -> List[Dict[str, str]]:
    """提取 Word 文档中的章节标题和对应级别"""
    doc = Document(file_path)
    headings = []

    for para in doc.paragraphs:
        style = para.style.name
        if style.startswith("Heading"):
            level = style.replace("Heading ", "")  # 如 Heading 1 -> 1
            headings.append({
                "level": level,
                "text": para.text.strip()
            })

    return headings

def main():
    path=Path("D:\\hbyt\\AI智能投标\\能力组件-附件\\研发特有_沟通管理及问题事件响应机制_v1.0_2201.docx")
    doc=extract_headings(path)
    print(doc)
if __name__ == '__main__':
    main()